//package org.activoricordi.app.snippet
package edu.ucdavis.fiehnlab.alchemy.alchemyAdmin.snippet

/**
 * Created with IntelliJ IDEA.
 * User: naru
 * Date: 3/28/13
 * Time: 4:18 PM
 * To change this template use File | Settings | File Templates.
 */
import edu.ucdavis.fiehnlab.alchemy.alchemyAdmin.model._
import net.liftweb._
import http.S
import net.liftweb.common.{Box,Full,Empty,Failure,ParamFailure}


import net.liftweb._
import http._
import SHtml._
import S._

import js._
import JsCmds._

import mapper._

import util._
import Helpers._

import scala.xml.{NodeSeq, Text}


import scala.xml._

class AddMethod {

  def create(form : NodeSeq): NodeSeq = {
    val method = new Method()

    /**
     * create a forum to input Method
     */
   // method.toForm(Full("save"), {_.save})
    def processEntryAdd () {
      /**
       *
       * validate input data
       */
      method.validate match {
      case Nil =>  method.save
      case errors:List[FieldError] => S.error(errors)
    }
    S.redirectTo("/method/list")}

   // method mapFieldTitleForm  ({  i =>
   def doBind(form: NodeSeq) =
    bind("method", form,
      "name" -> method.name.toForm,
      "riWindow" ->  method.riWindow.toForm,
      "mass" -> method.massWindow.toForm,
      "description" -> method.description.toForm,
      "submit" -> submit("Add", processEntryAdd))
   // })     openOr Text("Invalid Item")
    doBind(form)
  }
}
